package com.zipking.cloud.springbootmybatis.current;

import java.util.concurrent.atomic.AtomicInteger;

public class MessageNotificationCounter {
    private final AtomicInteger messageCount = new AtomicInteger(0);

    // 接收新消息时调用此方法
    public void receiveMessage() {
        // 原子地增加消息计数
        messageCount.incrementAndGet();
        System.out.println("New message received. Total messages: " + messageCount.get());
    }

    // 用户阅读消息时调用此方法
    public void messagesRead() {
        // 原子地减少消息计数
        messageCount.decrementAndGet();
        System.out.println("Messages read. Remaining messages: " + messageCount.get());
    }

    // 获取当前消息计数
    public int getMessageCount() {
        return messageCount.get();
    }
}


